<form action="" method="post">

  <input type="button" value="全选" onclick="setAll()" />
  <input type="button" value="反选" onclick="Inverse()" />
  <input type="button" value="全不选" onclick="setNo()" />
  <br />
  <input type="checkbox" name="love" /><br />
  <input type="checkbox" name="love" /><br />
  <input type="checkbox" name="love" /><br />
  <input type="checkbox" name="love" /><br />
  <input type="checkbox" name="love" /><br />
</form>
</body>
<!-- 首先弄好 全选 反选 和不全选 设置他们的函数  然后链接起来 -->
<script type="text/javascript">
  //全选函数
  function setAll() {
    var loves = document.getElementsByName("love");
    for (var i = 0; i < loves.length; i++) {
      loves[i].checked = true;
    }
  }

  //全不选函数
  function setNo() {
    var loves = document.getElementsByName("love");
    for (var i = 0; i < loves.length; i++) {
      loves[i].checked = false;
    }
  }

  //反选
  function Inverse() {
    var loves = document.getElementsByName("love");
    for (var i = 0; i < loves.length; i++) {
      if (loves[i].checked == false)
        loves[i].checked = true;
      else
        loves[i].checked = false;
    }
  }
</script>